import java.util.*;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    //联系linkedlist
    public static void main(String[] args) {
        List<String> list1=new ArrayList<>();
        list1.add("aaa");
        list1.add("bbb");
        list1.add("ccc");
        List<String> list2=new LinkedList<>(list1);
        System.out.println(list2);
        System.out.println("==============");

        list2.add("dzj");
        list2.add(1,"hzp");
        list2.addAll(list1);
        System.out.println(list2);
        System.out.println("==========");
        list2.remove(1);
        list2.remove("ccc");
        System.out.println(list2);
        System.out.println("==========");
        System.out.println(list2.get(2));
        list2.set(2,"hhh");
        System.out.println(list2.get(2));
        System.out.println(list2.contains("dzj"));
        System.out.println(list2.indexOf("ccc"));
        System.out.println(list2.lastIndexOf("aaa"));
        System.out.println("==========");
        List<String> subList=list2.subList(0,2);
        subList.set(1,"hsc");
        System.out.println(subList);
        System.out.println(list2);

        //LinkedList的遍历
        List<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(6);
        list.add(7);
        list.add(8);
        list.add(9);
        list.add(10);
        System.out.println(list.size());
        System.out.println("===========");
        for(Integer x:list){
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("===========");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println("===========");
        ListIterator<Integer> iterator = list.listIterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next()+" ");
        }
        System.out.println();
        System.out.println("===========");
        ListIterator<Integer> rit =list.listIterator(list.size());
        while(rit.hasPrevious()){
            System.out.print(rit.previous()+" ");
        }
        System.out.println();
        System.out.println("===========");
        iterator = list.listIterator();
        while(iterator.hasNext()){
            iterator.next();
            iterator.add(100);
        }
        System.out.println(list);

    }
}